import maya.cmds as cmds
import maya.mel as mel
class DangSonError(Exception):
	pass
viewport = cmds.getPanel( wf=True ) #active panel
try:
	cam = cmds.modelPanel( viewport, q=True, camera = True ) #current camera
	shelf = cmds.tabLayout( (mel.eval('$tempvar = $gShelfTopLevel')), st=True, query = True )
	existing = cmds.shelfLayout( shelf , q=True, ca=True )
	shelfbutton = cam+'Cam'
	if shelfbutton not in existing: #isn't there
		text = "You don't have a shelf icon for '"+cam+"' in the shelf yet.\nWant one?"
		if cmds.confirmDialog(title='Dang Son...', message=text) == 'Confirm':
			print 'Shelf Icon Created'
			code = """import maya.cmds as cmds
if cmds.objExists('%s'):
	cmds.lookThru('%s', cmds.getPanel( wf=True ))""" %(cam, cam)
			button = cmds.shelfButton( shelfbutton , p=shelf, image='cameraAim.png', l= cam, c=code)
except RuntimeError:
	raise DangSonError('There was an issue, grab a tissue. Gonna be a long night...')
